import React, { useState, useEffect } from 'react';
import type { FormProps } from 'antd';
import {
    Button,
    Cascader,
    DatePicker,
    Form,
    Input,
    InputNumber,
    Radio,
    Select,
    Switch,
    TreeSelect,
} from 'antd';

import { http_add, http_edit } from '../../api/http';


const Myform: React.FC = (props) => {
    console.log(props);


    const [form] = Form.useForm();
    const [data, setData] = useState([])


    useEffect(() => {
        if (props.title == '编辑') {
            form.setFieldsValue(props.objitem)
        }
    })

    const onFinish: FormProps<any>['onFinish'] = (values) => {
        if (props.title == '添加') {
            let obj = {
                id: new Date().getTime(),
                ...values,
            }
            http_add(obj)
        } else {
            let obj = {
                ...props.objitem,
                ...values
            }
            http_edit(obj)
        }
        props.onCancel()
    }

    return (
        <Form
            form={form}
            onFinish={onFinish}
            labelCol={{ span: 4 }}
            wrapperCol={{ span: 14 }}
            style={{ maxWidth: 600 }}
        >
            <Form.Item label="商机标题" name='title'
                rules={[{
                    required: true,
                    message: '请输入商机标题'
                }]}
            >
                <Input />
            </Form.Item>
            <Form.Item label="关联客服" name='name'
                rules={[{
                    required: true,
                    message: '请输入关联客服'
                }]}
            >
                <Input />
            </Form.Item>
            <Form.Item label="商业阶段" name='stage'
                rules={[{
                    required: true,
                    message: '请输入商业阶段'
                }]}
            >
                <Input />
            </Form.Item>
            <Form.Item label="播报记录" name='total'
                rules={[{
                    required: true,
                    message: '请输入播报记录'
                }]}
            >
                <Input />
            </Form.Item>
            <Form.Item label="报价总金额" name='price'
                rules={[{
                    required: true,
                    message: '请输入报价总金额'
                }]}
            >
                <Input />
            </Form.Item>
            <Form.Item label="最后跟进" name='time'
                rules={[{
                    required: true,
                    message: '请输入最后跟进'
                }]}
            >
                <Input />
            </Form.Item>
            <Form.Item label="未跟进天数" name='day'
                rules={[{
                    required: true,
                    message: '请输入未跟进天数'
                }]}
            >
                <Input />
            </Form.Item>
            <Form.Item label={null}>
                <Button type="primary" htmlType="submit">
                    确定
                </Button>
            </Form.Item>
        </Form>
    );
};

export default Myform;